/**
 * @Author lq
 * @Description:
 * @Param:
 * @Return:
 * @Create: 2022/8/22$ 10:37$
 */

package com.bw.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootConfiguration
public class MyWebMvcConfig implements WebMvcConfigurer {


    //全局解决跨域
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        //允许跨域访问的路径
//        registry.addMapping("/**")
//                //允许跨域访问的源
//                .allowedOrigins("*")
//                //允许的请求方法  也可以写 *
//                .allowedMethods("POST", "GET", "PUT", "DELETE", "OPTIONS")
//                //预检间隔时间  每次请求会发起两次 第一次是预检请求 前锋 先去看是否允许跨域
//                .maxAge(16800)
//                //允许头部设置
//                .allowedHeaders("*")
//                //是否发送cookie
//                .allowCredentials(true);
//    }


    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //分页
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        //乐观锁
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }

   
}
